<template>
	<div class="home-main">
		<div class="home-bg"></div>
		<div class="home-box">
			<div class="home-info">
				<i class="icon-a1"></i>
				<i class="icon-a2"></i>
				<h2>金蚁货币现市场价值</h2>
				<p>拥有金蚁公司货币，优先享受公司上市后原始股的购买权限 公司筹备上市预期在2021年中旬 公司上市期间即可按照货币比例购买原始股权和上市后的股票</p>
				<ul>
					<li v-for="(kl, index) in list" :key="index" class="flex">
						<em>{{ kl.value }}JYB</em>
						<i>兑换比例</i>
						<em class="act">￥{{ kl.value }}</em>
						<a @click="playInfoType(kl, true)">立即购买</a>
					</li>
				</ul>
			</div>
			<div class="home-info">
				<label><span>期权股</span></label>
				<p class="act">
					期权股是公司上市之前给家人们购买的股权 期权股是让购买原价值货币乘以2 可提现原价货币的百分之三十期权股到期时间是公司上市时间为截止 期权股是享受公司上市前产生的利润分红
				</p>
				<h3>￥900</h3>
				<a @click="playInfoCk('900', false)"><van-btn text="立即购买" type="1" /></a>
			</div>
			<div class="home-info">
				<label><span>奖励机制</span></label>
				<h5>推荐购买成功可获得百分之二十的佣金返还奖励</h5>
				<p>1.推荐购买成功30人奖励标准1000元</p>
				<p>2.推荐购买成功50人奖励标准2000元</p>
			</div>
		</div>
		<van-dialog v-model="showType" title="确认购买" confirmButtonColor="#f98a42" show-cancel-button>
			<van-form class="ks-info">
				<van-field v-model="from.t1" readonly type="text" label="购买币" />
				<van-field v-model="from.t2" readonly type="text" maxlength="10" label="可用佣金" />
				<van-field v-model="from.t3" type="digit" maxlength="10" label="抵扣佣金" placeholder="请输入抵扣佣金" />
				<p @click="cinfigCheck"></p>
			</van-form>
		</van-dialog>
	</div>
</template>

<script>
import vanBtn from '../common/vanBtn';
import { requeSubmitPay, getFinancialInfo } from '@/api/';
export default {
	components: {
		vanBtn
	},
	data() {
		return {
			showType: false,
			from: {
				t1: '',
				t2: 0,
				t3: '',
				type: ''
			},
			list: [
				{
					value: '800'
				},
				{
					value: '1200'
				},
				{
					value: '1800'
				}
			]
		};
	},
	created() {
		document.title = '首页';
		if (localStorage.getItem('userInfo')) {
			getFinancialInfo({})
				.then(res => {
					if (res.code === 200 && res.data) {
						this.from.t2 = res.data.mayWithdrawAmt;
					}
				})
				.catch(msg => {});
		}
	},
	methods: {
		playInfoType(row, t) {
			this.from.type = t;
			this.from.t1 = row.value;
			this.from.t3 = '';
			this.showType = true;
		},
		playInfoCk(v, t) {
			this.from.t1 = v;
			this.from.type = t;
			this.from.t3 = '';
			this.playInfo();
		},
		cinfigCheck() {
			if (!localStorage.getItem('userInfo')) {
				this.login();
				return;
			}
			if (this.from.t3 && Number(this.from.t3) > Number(this.from.t2)) {
				this.toast('可用佣金不足');
				this.showType = true;
				return;
			}
			if (this.from.t3 && Number(this.from.t3) > Number(this.from.t1)) {
				this.toast('抵押金额已超过购买币');
				this.showType = true;
				return;
			}
			if (this.from.t3 && this.from.t3 !== '0' && this.from.t1 !== '0' && Number(this.from.t3) === Number(this.from.t1)) {
				this.$dialog
					.confirm({
						title: '温馨提示',
						message: '确认要全额抵扣吗？',
						confirmButtonColor: '#f98a42'
					})
					.then(() => {
						this.playInfo();
					})
					.catch(() => {});
			} else {
				this.playInfo();
			}
		},
		async playInfo() {
			this.$toast.loading({
				message: '数据提交中...',
				forbidClick: true,
				duration: 0,
				loadingType: 'spinner'
			});
			this.showType = false;
			const res = await this.getInfo({
				orderAmt: this.from.t1,
				coupon: this.from.t3,
				orderType: this.from.type ? '0' : '1',
				orderNum: '1'
			});
			if (res.code === 200) {
				//发起跳转
				this.$toast.clear();
				if (res.data.payUrl) {
					window.location.href = res.data.payUrl;
				} else {
					this.toast('购买成功');
					setTimeout(() => {
						location.reload();
					}, 1000);
				}
			} else if (res.code && res.code !== 200 && res.code !== 601) {
				this.$toast.clear();
				this.toast(res.msg || ' 请求失败');
			}
		},
		getInfo(row) {
			// orderNum固定1，orderType：0：金币购买，1：期权股购买
			return new Promise((resolve, reject) => {
				requeSubmitPay(row)
					.then(res => {
						resolve(res);
					})
					.catch(msg => {
						resolve(false);
					});
			});
		},
		login() {
			this.$toast({
				message: '尚未登录',
				position: 'bottom'
			});
			setTimeout(() => {
				this.$router.push({
					path: '/Login',
					query: {}
				});
			}, 1200);
		}
	}
};
</script>

<style scoped lang="less">
.home-main {
	margin-bottom: 140px;
	.home-bg {
		position: absolute;
		left: 0;
		top: 0;
		height: calc(100vh + 600px);
		width: 100%;
		background: url(../../assets/images/bg_home.png) no-repeat;
		background-size: 100%;
		z-index: 0;
	}
	.home-box {
		position: relative;
		margin-top: 40%;
		padding: 0 8%;
		z-index: 1;
		.home-info {
			background: #fffcf6;
			border-radius: 20px;
			padding: 3%;
			margin-bottom: 6%;
			position: relative;
			.icon-a1 {
				position: absolute;
				left: 12%;
				top: -30px;
				width: 60px;
				height: 60px;
				background: url(../../assets/images/icon_home_a.png) no-repeat;
				background-size: 100%;
			}
			.icon-a2 {
				position: absolute;
				right: -40px;
				top: 40px;
				width: 90px;
				height: 90px;
				background: url(../../assets/images/icon_home_b.png) no-repeat;
				background-size: 100%;
			}
			> label {
				width: 216px;
				height: 60px;
				margin: -20px auto 0 auto;
				background: url(../../assets/images/icon_title.png) no-repeat;
				background-size: 100%;
				display: block;
				> span {
					text-align: center;
					display: inline-block;
					width: 100%;
					line-height: 60px;
					font-size: 28px;
					font-family: PingFang SC;
					font-weight: bold;
					color: #7e552b;
				}
			}
			> h2 {
				text-align: center;
				font-size: 35px;
				font-weight: 600;
				padding: 4% 0 3% 0;
			}
			> h3 {
				font-size: 36px;
				text-align: center;
				color: #f32828;
				font-weight: bold;
				padding-top: 3%;
			}
			> a {
				padding-top: 5%;
				display: block;
			}
			> h4 {
				text-align: center;
				font-size: 24px;
				padding-bottom: 10px;
			}
			> h5 {
				padding: 5% 0 2% 0;
				font-size: 28px;
				text-align: center;
			}
			> p {
				text-indent: 2em;
				font-size: 26px;
				line-height: 40px;
				&.act {
					padding-top: 5%;
				}
			}
			> ul {
				> li {
					padding: 3% 0;
					> em {
						width: 24%;
						padding-top: 1%;
						text-align: right;
						color: #f32828;
						font-weight: bold;
						font-size: 30px;
						display: inline-block;
						&.act {
							text-align: left;
						}
					}
					> i {
						width: 20%;
						text-align: center;
						font-size: 20px;
						position: relative;
						top: 12px;
						&:after {
							content: '';
							position: absolute;
							left: 5%;
							right: 5%;
							bottom: 22px;
							border-bottom: 2px solid #eee;
						}
					}
					> a {
						padding: 1.6% 5%;
						font-size: 24px;
						background: linear-gradient(to right, #fad27d, #f98a42);
						color: #fff;
						border-radius: 44px;
					}
				}
			}
		}
	}
}
</style>
<style>
.ks-info > p {
	position: absolute;
	left: 50%;
	right: 0;
	height: 1.2rem;
	z-index: 999;
	bottom: 0;
}
.ks-info .van-cell {
	padding: 3.5% 16px;
}
.ks-info .van-cell::after {
	border-bottom: 2px solid #eee;
}
.ks-info .van-field__label {
	font-size: 0.38rem;
	color: #333;
	font-weight: 500;
	text-align: right;
}
.ks-info .van-field__control {
	font-weight: 500;
}
</style>
